﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XoLib.Convertion;

namespace XoLibCSharpText
{
    [TestClass]
    public class TestConvertion
    {

        [TestMethod]
        public void CalculAddressMac()
        {
            string[] ListTest = new string[] {   
                "00:17:23:14:32:75:00:00", 
                "FF:17:23:14:32:75:4C:AE",
                "FF:FF:FF:FF:FF:FF:FF:FF",
                "00:00:00:00:00:00:00:00",
            };


            foreach (string test in ListTest)
            {
                long l = StringAndLong.StringToLong(test, ':', 16);
                string s = StringAndLong.LongToString(l, 8, ':', 16);

                Assert.AreEqual( MacAddress.LongToString(MacAddress.StringToLong(test)) , test);
                Assert.AreEqual(test, s);
            }
        }

        [TestMethod]
        public void CalculAddressIp()
        {
            string[] ListTest = new string[] {   
                "192.1.2.75", 
                "130.3.0.128",
                "10.7.250.140",
                "255.255.255.0",
                "1.1.1.1",
            };


            foreach (string test in ListTest)
            {
                long l = StringAndLong.StringToLong(test, '.', 10);
                string s = StringAndLong.LongToString(l, 4, '.', 10);

                Assert.AreEqual(IPAddress.LongToString(IPAddress.StringToLong(test)), test);
                Assert.AreEqual(test, s);
            }


        }

        [TestMethod]
        public void RegexTest1()
        {
            string value = "806)UE_125)Resultat112012";

            RegexFileChaine RegxTest = new RegexFileChaine();
            RegxTest.Decoupe(value);

            Assert.AreEqual(value, RegxTest.Original);
            Assert.AreEqual(@"^\d{3}\)UE_\d{3}\)Resultat\d{6}$", RegxTest.Filtre);
            Assert.AreEqual(@"(0,3)+(4,2)+""_""+(7,3)+(11,8)+(19,6)", RegxTest.Script);
        }


        [TestMethod]
        public void RegexTest2()
        {
            string value = "806)UE_125)Resultat112012";

            RegexFileChaine RegxTest = new RegexFileChaine();
            RegxTest.Decoupe(value);

            Assert.AreEqual(value, RegxTest.Original);
            Assert.AreEqual(@"^\d{3}\)UE_\d{3}\)Resultat\d{6}$", RegxTest.Filtre);
            Assert.AreEqual(@"(0,3)+(4,2)+""_""+(7,3)+(11,8)+(19,6)", RegxTest.Script);
        }

    }
}
